﻿using AutoMapper;
using Comm100.Application.Services;
using Comm100.Framework.Auditing;
using Comm100.Framework.Authorization;
using Comm100.Public.Audit;
using Bot.Application.Dto;
using Bot.Application.Services;
using Bot.Domain.Bo;
using Bot.Domain.Entities;
using Bot.Domain.Interfaces;
using System;
using System.Collections.Generic;
using System.Text;
using Bot.Domain;

namespace Bot.Application.GreetingMessageInChannels.Service
{
    public class GreetingMessageInChannelAppService : BaseAppService, IGreetingMessageInChannelAppService
    {
        private IGreetingMessageInChannelDomainService _domainService;

        public GreetingMessageInChannelAppService(IGreetingMessageInChannelDomainService domainService) : base()
        {
            this._domainService = domainService;
        }

        [Authorization(BotPermission.MANAGE_BOTS)]
        //[Audit(BotEntity.GREETINGMESSAGEINCHANNEL, AuditAction.DESTROY)]
        public void Delete(Guid id)
        {
            _domainService.Delete(id);
        }

        [Authorization(BotPermission.MANAGE_BOTS)]
        //[Audit(BotEntity.GREETINGMESSAGEINCHANNEL, AuditAction.CREATE)]
        public GreetingMessageInChannelDto Add(Guid botId, GreetingMessageInChannelCreateDto dto)
        {
            dto.BotId = botId;
            GreetingMessageInChannel greetingMessageInChannel = _domainService.Create(Mapper.Map<GreetingMessageInChannel>(dto));
            return Mapper.Map<GreetingMessageInChannelDto>(greetingMessageInChannel);
        }

        [Authorization(BotPermission.MANAGE_BOTS)]
        //[Audit(BotEntity.GREETINGMESSAGEINCHANNEL, AuditAction.UPDATE)]
        public GreetingMessageInChannelDto Update(Guid id, GreetingMessageInChannelUpdateDto dto)
        {
            var greetingMessageInChannelUpdateBo = Mapper.Map<GreetingMessageInChannelUpdateBo>(dto);
            greetingMessageInChannelUpdateBo.Id = id;
            _domainService.Update(greetingMessageInChannelUpdateBo);
            var greetingMessageInChannel = Get(id, "responses");
            return Mapper.Map<GreetingMessageInChannelDto>(greetingMessageInChannel);
        }

        public GreetingMessageInChannelDto Get(Guid id, string include="")
        {
            GreetingMessageInChannel greetingMessageInChannel = _domainService.GetById(id, include);
            return Mapper.Map<GreetingMessageInChannelDto>(greetingMessageInChannel);
        }

        public IEnumerable<GreetingMessageInChannelDto> GetList(Guid botId, string include = "")
        {
            IEnumerable<GreetingMessageInChannel> list = _domainService.GetByBotId(botId, include);
            return Mapper.Map<IEnumerable<GreetingMessageInChannelDto>>(list);
        }
    }
}
